
function SelCity(obj,e) {
    var ths = obj;
    var dal = '<div class="_citys"><div class="citys1title">选择配件</div><ul id="_citysheng" class="_citys0"><li class="citySel" id="sheng">选择产品组</li><li id="shi">选择产品</li><li id="xian">选择配件</li></ul><div id="_citys0" class="_citys1"></div><div style="display:none" id="_citys1" class="_citys1"></div><div style="display:none" id="_citys2" class="_citys1"></div></div>';
    Iput.show({ id: ths, event: e, content: dal,width:"470"});
    var tb_province = [];
    // var b = province;//test
    var b = [];
    //同步加载产品组数据
    $.ajax({
        url:COMMON_URL + "/getProduct",
        async:false,
        typ:'GET',
        data:{key:"group"},
        success:function(res){
            b = res.data;
        }
    });

    for (var i = 0, len = b.length; i < len; i++) {
        tb_province.push('<a  data-level="0" data-id="' + b[i]['id'] + '" data-name="' + b[i]['name'] + '">' + b[i]['name'] + '</a>');
    }
    $("#_citys0").append(tb_province.join(""));
    $("#_citys0 a").click(function () {
        var g = getCity($(this));
        $("#_citys1 a").remove();
        $("#_citys1").append(g);
        $("._citys1").hide();
        $("._citys1:eq(1)").show();
        var lev = $(this).data("name");
        $("#product1").html($(this).data("name")).css("color","#333");
        $("#hproper").remove();
        $("#harea").remove();
        if (document.getElementById("hcity") == null) {
            var hcitys = $('<input>', {
                type: 'hidden',
                name: "hcity",
                "data-id": $(this).data("id"),
                id: "hcity",
                val: lev
            });
            $(ths).after(hcitys);
        }
        else {
            $("#hcity").val(lev);
            $("#hcity").attr("data-id", $(this).data("id"));
        }
        $("#_citys1 a").click(function () {
            var lev =  $(this).data("name");
            $("#shi").html(lev);
            $("#harea").remove();
            if (document.getElementById("hproper") == null) {
                var hcitys = $('<input>', {
                    type: 'hidden',
                    name: "hproper",
                    "data-id": $(this).data("id"),
                    id: "hproper",
                    val: lev
                });
                $(ths).after(hcitys);
            }
            else {
                $("#hproper").attr("data-id", $(this).data("id"));
                $("#hproper").val(lev);
            }
            var bc = $("#hcity").val();
            $("#product2").html($(this).data("name")).css("color","#333");

            var ar = getArea($(this));

            $("#_citys2 a").remove();
            $("#_citys2").append(ar);
            $("._citys1").hide();
            $("._citys1:eq(2)").show();

            $("#_citys2 a").click(function () {
                var lev = $(this).data("name");
                $("#xian").html(lev);
                if (document.getElementById("harea") == null) {
                    var hcitys = $('<input>', {
                        type: 'hidden',
                        name: "harea",
                        "data-id": $(this).data("id"),
                        id: "harea",
                        val: lev
                    });
                    $(ths).after(hcitys);
                }
                else {
                    $("#harea").val(lev);
                    $("#harea").attr("data-id", $(this).data("id"));
                }
                var bc = $("#hcity").val();
                var bp = $("#hproper").val();
                // $("#product3").html($(this).data("name")).css("color","#333");
                //动态加载免邮件費配件
                if($(this).data("name")&&obj.id=='city'){
                    // mask.close();
                    var type=$(this).data("name");
                    var money=$(this).data("price");
                    document.getElementById('pro').style.display='block';
                    // $("#pro").append('<div class="zoomImage" style="background-image:url(' + url + ')" value="'+file.name+'"></div>');
                    $("#pro").append('<div class="idm">'+'<div class="type product" style="float: left;width: 95%">'+type+'</div>' +'<a onclick="del()"><div class="fa fa-close" style="width: 5%;float: right;color:#c6c6c7 "></div>'+'</a>'+
                        '<div style="width:100%;color: red;float: right;padding-left:80%" class="money" val = '+money+'>'+money+'&yen'+'</div>'+
//                      '<div class="new">新码： <img src="../../plugin/rewrite/img/scanner.png" style="width: 1rem;height:1rem"></div>'+
//                      '<div class="old">旧码： <img src="../../plugin/rewrite/img/scanner.png" style="width: 1rem;height:1rem"></div>'+'</div>');

						'<div class="new">新码： <span>2345678</span></div>'+
                        '<div class="old">旧码： <span>234522278</span></div>'+'</div>');
          

                }
                // if($(this).data("name")&&obj.id=='city1'){
                //     var type=$(this).data("name");
                //     var money=$(this).data("price")+'&yen';
                //     document.getElementById('pro1').style.display='block';
                //     // $("#pro").append('<div class="zoomImage" style="background-image:url(' + url + ')" value="'+file.name+'"></div>');
                //     $("#pro1").append('<div id="ids">'+'<div id="product3" class="type" style="float: left;width: 95%">'+type+'</div>' +'<a onclick="del()"><div class="fa fa-close" style="width: 5%;float: right;color:#c6c6c7 "></div>'+'</a>'+
                //         '<div style="width:100%;color: red;float: right;padding-left:80%">'+money+'</div>'+
                //         '<div class="new">新码： <img src="../../plugin/rewrite/img/scanner.png" style="width: 1rem;height:1rem"></div>'+
                //         '<div class="old">旧码： <img src="../../plugin/rewrite/img/scanner.png" style="width: 1rem;height:1rem"></div>'+'</div>');
                // }

                // $("#price").html($(this).data("price")+'&yen').css("color","#333");

                Iput.colse();
                mask.close();

            });

        });
    });
    $("#_citysheng li").click(function () {
        $("#_citysheng li").removeClass("citySel");
        $(this).addClass("citySel");
        var s = $("#_citysheng li").index(this);
        $("._citys1").hide();
        $("._citys1:eq(" + s + ")").show();
    });
}

//删除配件
function del() {
    // console.log(1);
    // console.log($(event.target));
    $(event.target).parent().parent().remove()
}
//记住产品信息
var product = [];
function getCity(obj) {
    var c = obj.data('id');
    // var e = province;
    var e = [];
    //同步加载产品组数据
    $.ajax({
        url:COMMON_URL + "/getProduct",
        async:false,//同步
        typ:'GET',
        data:{ key: "serial-" + c},
        success:function(res){
            e = res.data;
            product = res.data;
        }
    });
    var g = '';
    console.log('324');
    for (var j = 0; j < e.length; j++) {
        g += '<a data-level="1" data-id="' + e[j]['id'] + '" data-name="' + e[j]['name'] + '" title="' + e[j]['name'] + '">' + e[j]['name'] + '</a>'
    }
    $("#_citysheng li").removeClass("citySel");
    $("#_citysheng li:eq(1)").addClass("citySel");
    return g;
}
function getArea(obj) {
    var c = obj.data('id');
    // var e = area;
    var e = product;
    var f = [];
    var g = '';
    for (var i = 0, plen = e.length; i < plen; i++) {
        if (e[i].id == parseInt(c)) {
            f = e[i].content;
            break;
        }
    }
    for (var j = 0, clen = f.length; j < clen; j++) {
        g += '<a data-level="1" data-id="' + f[j]['id'] + '" data-name="' + f[j]['name'] + '" data-price='+ f[j].money+' title="' + f[j]['name'] + '">' + f[j]['name'] + '</a>'
    }

    $("#_citysheng li").removeClass("citySel");
    $("#_citysheng li:eq(2)").addClass("citySel");
    return g;
}